package br.edu.unibratec.viagemfacil;

import java.util.List;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class ListaFavoritosFragment extends ListFragment {

	List<Frase> frasesFavoritas;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		setRetainInstance(true);
	}
	
	@Override
	public void onResume() {
		super.onResume();
		refreshList();
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		if (getActivity() instanceof ClicouNaCategoria){
			((ClicouNaCategoria)getActivity()).CategoriaFoiClicada(frasesFavoritas.get(position));
		}
	}

	protected void refreshList() {
		FraseDB db = new FraseDB(getActivity());
		frasesFavoritas = db.todosAsFrases();
		
		FraseAdapter adapter = new FraseAdapter(getActivity(), frasesFavoritas);
		setListAdapter(adapter);
	}
}